﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using Database.Entities;

namespace Database
{
    public class EmployeeContext : DbContext, IDisposable
    {
        public DbSet<Employee> Employees { get; set; }
        public DbSet<Department> Departments { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new EmployeeConfiguration()).
                                        Add(new AddressConfiguration());


            base.OnModelCreating(modelBuilder);
            
        }
    }
    public class EmployeeConfiguration : EntityTypeConfiguration<Employee>
    {
        public EmployeeConfiguration()
        {
            Property(d => d.Name).HasMaxLength(200);
            Property(d => d.WageType).HasColumnName("WageType");
        }
    }

    public class AddressConfiguration : ComplexTypeConfiguration<Address>
    {
        public AddressConfiguration()
        {
            Property(p => p.City).HasMaxLength(50);
        }
    }

}
